Re: [SQL] SubQuery speed - Mailing list pgsql-sql

From Herouth Maoz
Subject Re: [SQL] SubQuery speed
Date
Msg-id l03110703b21af7eb7bd6@[147.233.159.109]
Whole thread Raw
In response to SubQuery speed  (andreas.fredriksson@pacer.se)
List pgsql-sql
At 16:45 +0200 on 8/9/98, andreas.fredriksson@pacer.se wrote:


> Are there any alternate methods of solving this? I don't think it's
> possible to write this kind of query using a multi-JOIN?

Why not? So long as the query is "in", and not "not in"?

Should be something like:

SELECT DISTINCT url,title
FROM idx_files, idx_ref, idx_words
WHERE idx_files.id = idx_ref.file_id
  AND idx_ref.word_id = idx_words.id
  AND (idx_words.word = 'search term 1' OR .. );

In any case, are there indices on the appropriate fields?

If the innermost query is supposed to return only one tuple, you should use
"=" rather than IN, although I don't know how much that adds. The optimizer
probably has an easier time with "=" than with IN.

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma



pgsql-sql by date:

Previous
From: "Kevin O' Gorman"
Date:
Subject: Re: [SQL] Looking for easy SQL documentation!
Next
From: Leslie Mikesell
Date:
Subject: Re: [SQL] Looking for easy SQL documentation!